part of '../widget.dart';

class _{{widgetName.pascalCase()}}Theme extends InheritedTheme {
  _{{widgetName.pascalCase()}}Theme({
    required Brightness brightness,
    required super.child,
  })  : _brightness = brightness,
        _data = _buildThemeData(
          brightness: brightness,
        );

  final Brightness _brightness;
  final _{{widgetName.pascalCase()}}ThemeData _data;

  static _{{widgetName.pascalCase()}}ThemeData _buildThemeData({
    required Brightness brightness,
  }) {
    return switch (brightness) {
      _ => _{{widgetName.pascalCase()}}ThemeData.dark(),
    };
  }

  static _{{widgetName.pascalCase()}}ThemeData of(BuildContext context) {
    final inheritedTheme = context.dependOnInheritedWidgetOfExactType<_{{widgetName.pascalCase()}}Theme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme = context.findAncestorWidgetOfExactType<_{{widgetName.pascalCase()}}Theme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return _{{widgetName.pascalCase()}}Theme(
      brightness: _brightness,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(_{{widgetName.pascalCase()}}Theme oldWidget) {
    return _brightness != oldWidget._brightness;
  }
}

class _{{widgetName.pascalCase()}}ThemeData {
  const _{{widgetName.pascalCase()}}ThemeData._internal({
    required this.textTheme,
  });

  factory _{{widgetName.pascalCase()}}ThemeData.dark() {
    return _{{widgetName.pascalCase()}}ThemeData._internal(
      textTheme: _{{widgetName.pascalCase()}}TextTheme.dark(),
    );
  }

  final _{{widgetName.pascalCase()}}TextTheme textTheme;
}
